<template>
  <div>
    <!--以下是审批字段-->
<!--    <div v-show="type === 'todo'">
      <el-form label-width="100px">
        <el-divider></el-divider>
        <el-form-item label="审批意见">
          <el-radio-group v-model="pass">
            <el-radio label="true">同意</el-radio>
            <el-radio label="false">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="批注" prop="remark">
          <el-input v-model="comment" type="textarea" :value="comment" />
        </el-form-item>
      </el-form>
    </div>-->
    <!--以下是审批字段-->

    <!--以下是审批改造字段-->
    <div v-show="type === 'todo'">
      <el-form  ref="form" :rules="rules" label-width="100px">
        <el-divider></el-divider>
        <el-form-item v-if="taskName==='接单确认'" :label="taskName">
          <el-radio-group v-model="pass">
            <el-radio label="true">接单</el-radio>
            <el-radio label="false">退单</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item v-if="taskName==='维保签到'" :label="taskName">
          <el-radio-group v-model="pass">
            <el-radio label="true">签到</el-radio>
            <el-radio label="false">退单</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item v-if="taskName.includes('退单审核')" :label="taskName" >
        <el-radio-group v-model="pass">
          <el-radio label="true">同意</el-radio>
          <el-radio label="false">驳回</el-radio>
        </el-radio-group>
      </el-form-item>

        <el-form-item v-if="taskName==='是否重新分配'" :label="taskName">
          <el-radio-group v-model="pass">
            <el-radio label="true">是</el-radio>
            <el-radio label="false">否</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item v-if="taskName==='回访确认'" :label="taskName">
          <el-radio-group v-model="pass">
            <el-radio label="true">回访</el-radio>
            <el-radio label="false">不回访</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item v-if="taskName==='重新分配'" :label="taskName">
        后台默认重新分配给rensm
        </el-form-item>

        <el-form-item label="批注" prop="remark">
          <el-input v-model="comment" type="textarea" :value="comment" />
        </el-form-item>
      </el-form>
    </div>
    <!--以下是审批改造字段-->
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <el-button v-show="type === 'todo'" type="primary" @click="complete">确 定</el-button>
      <el-button @click="close">关 闭</el-button>
    </div>
  </div>
</template>

<script>
  import request from '@/utils/request'

  export default {
    name: "ViewVerify",
    props: {
      row: {
        type: Object,
      },
      taskId: {
        type: String,
      },
      type: {
        type: String,
      },
      taskName: {
        type: String,
      },
    },
    data() {
      return {
        pass: null,
        comment: '',
      }
    },
    methods: {
      close: function () {
        this.$emit('update:open', false);
      },
      complete() {
        if(this.taskName=="维保回复"||this.taskName=="重新分配"||this.taskName=="客服回访"){
          this.pass="true"
        }
        if(this.pass==null){
          this.msgError("请选择"+this.taskName)
          return;
        }
        this.$parent.$children[0].validate(valid => {
          if (valid) {
            const data = {
              "taskId": this.taskId,
              "taskName": this.taskName,
              "instanceId": this.row.instanceId,
              "variables": JSON.stringify({
                "comment": this.comment,
                "pass": this.pass,
                "formData": this.row,
              }),
            };
            return request({
              url: '/activiti/process/complete',
              method: 'post',
              params: data
            }).then(response => {
              this.close();
              // 刷新待办事项列表（丑陋的代码 👇）
              this.$parent.$parent.$parent.$parent.$parent.$parent.getList();
              this.msgSuccess("操作成功");
            });
          }
        });
      },
    },
    watch: {
    pass: function(val) {
          if(this.taskName==='维保签到'){
            this.comment = val === 'true' ? '签到' : '退单';
          }else if(this.taskName==='接单确认'){
            this.comment = val === 'true' ? '接单' : '退单';
          }else if(this.taskName==='退单审核'){
            this.comment = val === 'true' ? '同意退单' : '驳回退单';
          }else if(this.taskName==='是否重新分配'){
            this.comment = val === 'true' ? '重新分配' : '不重新分配,结束';
          }else if(this.taskName==='回访确认'){
            this.comment = val === 'true' ? '回访' : '不回访,结束';
          }else if(this.taskName==='重新分配'){
            this.comment = "重新分配给rensm"
          }else if(this.taskName.includes('退单审核')){
            this.comment = val === 'true' ? '同意退单' : '不同意退单';
          }
        },
    },
  }
</script>

<style scoped>

</style>
